<template>
  <div class="dashboard_container">
    <div class="card-title">设备在线</div>
    <div class="card-main">
      <div>设备在线率</div>
      <div>{{ (deviceData.onlineRate * 100).toFixed(0) }}%</div>
    </div>
    <div class="card-foot">
      <div class="line">
        <div>接入总数</div>
        <div>{{ deviceData.total }}</div>
      </div>
      <div class="line">
        <div>在线</div>
        <div
          v-if="deviceData.onlineNumber > 0"
          class="jump_dom"
          @click="jumpPage('1')"
        >
          {{ deviceData.onlineNumber }}
          <img src="@/assets/images/jump_icon.png" alt="" />
        </div>
        <div v-else>{{ deviceData.onlineNumber }}</div>
      </div>
      <div>
        <div>离线</div>
        <div
          v-if="deviceData.offlineNumber > 0"
          class="jump_dom"
          @click="jumpPage('0')"
        >
          {{ deviceData.offlineNumber }}
          <img src="@/assets/images/jump_icon.png" alt="" />
        </div>
        <div v-else>{{ deviceData.offlineNumber }}</div>
      </div>
    </div>
    <div class="ball">
      <span> {{ (deviceData.onlineRate * 100).toFixed(0) }}%</span>
    </div>
  </div>
</template>

<script setup lang="tsx">
import { ref } from 'vue';
import router from '@/router';

const props = defineProps({
  deviceData: {
    type: Object,
    default: () => {},
  },
});

const jumpPage = (val: any) => {
  router.push({
    path: 'devices/allDevice',
    query: { onlineStatus: val },
  });
};
</script>

<style lang="scss" scoped>
@use '../style.scss';
.dashboard_container {
  background-image: url('@/assets/images/online-bg.png');
}
</style>
